package com.codeoss.framework.view.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.codeoss.framework.context.YunContext;
import com.codeoss.framework.expression.Expression;
import com.codeoss.framework.view.component.Component;
import com.codeoss.framework.view.component.TreePath;
import com.codeoss.framework.view.service.IVariableService;

@Service("treepathComponentService")
public class TreePathComponentService extends ComponentService {
	@Autowired
	private IVariableService variableService;

	@Override
	public void processValue(YunContext yunContext, Component component, Map<String, String> paraMap,
			Map<String, Object> dataMap) {
		// TODO Auto-generated method stub
		TreePath treePath = (TreePath) component;
		if (paraMap.containsKey(treePath.getId())) {
			String sValue = paraMap.get(treePath.getId());
			Long value=Long.parseLong(sValue);
			variableService.setVariableValue(yunContext, treePath.getVarName(), value);
		}
	}

	@Override
	public void processEvent(YunContext yunContext, Component component, String eventType) {
		super.processEvent(yunContext, component, eventType);
		TreePath treePath = (TreePath) component;
		if ("itemClickEvent".equals(eventType)) {
			Expression onItemClickExpression =treePath.getOnItemClickExpression();
			if (onItemClickExpression != null) {
				executeEventExpression(yunContext, component, onItemClickExpression,null);
			}
		}
	}
}
